<?php 
namespace XFCore\controllers\user;
use lib\{BaseController, Tips, Commontc};

class IndexController extends BaseController{
   public function __construct(){
       parent::__construct();
       
   }
   public function index(){
        if($this->islogin_user != 1)Commontc::falsetc("请先登录",rethreffun('/login',false));
        include usertem.'index.php';
   }
   public function login($get){
       if(isset($this->input->logout)){
        	setcookie("user_token", "", time() - 99999999999999999 , '/');
        	@header('Content-Type: text/html; charset=UTF-8');
        	Commontc::truetc("注销成功！",rethreffun('/login'));
        }
        if($this->islogin_user == 1)Commontc::truetc("您已登录！",rethreffun('/index'));
        if(($get['pid'] && $get['trade_no'] && $get['sign'] && $get['trade_status'] == 'TRADE_SUCCESS') || (!empty($get['token']))){
            Tips::success("注册成功！","注册成功","/user/login");
        }
        $loadfile = \lib\LoginTemplate::load("login");
        include $loadfile;
   }
   public function reg($get){
        if($this->islogin_user == 1)Commontc::truetc("您已登录！",rethreffun('/index'));
        if($this->conf->reg_open == 0){
            Commontc::falsetc("管理员未开启注册！",rethreffun('/login'));
        }
        $loadfile = \lib\LoginTemplate::load("reg");
        include $loadfile;
   }
   public function Retrieve(){
       if($this->islogin_user == 1)Commontc::truetc("您已登录！",rethreffun('/index'));
       include usertem.'Retrieve.php';
   }
   public function main($get){
       
       if($this->islogin_user != 1)Commontc::falsetc("请先登录",rethreffun('/login'));
       $my = $get['my'] ?:'';
       if($my == 'status'){
           if(!empty($this->conf['modal'])){
               exitjson(200,'success');
           }
           exitjson(-1,'error');
       }
       include usertem.'main.php';
   }
   
   public function order(){
       if($this->islogin_user != 1)Commontc::falsetc("请先登录",rethreffun('/login'));
       include usertem.'order.php';
   }
   public function qrlist($get){
       if($this->islogin_user != 1)Commontc::falsetc("请先登录",rethreffun('/login'));
       $my = $get['my'] ?:"list";
       $id = $get['id']?:"id";
       if($my== 'edit' && !empty($id)){
           $row = $this->db->qrlistrow($id);
           if($row && $row['pid'] == $this->uid){
               $app = '';
               $ckstatus = strlen($row['cookie'])>2 ? 'CooKie状态正常':'CooKie已失效，请勿强制开启二维码';
               if($row['cookie'] == 'xfqymckxy' || $row['cookie'] == 'xfqydmfxy'){
                   $app = generateAlipayInfo($row);
               }
           }
       }
       
       include usertem.'qrlist.php';
   }
   public function usdt($get){
       if($this->islogin_user != 1)Commontc::falsetc("请先登录",rethreffun('/login'));
       $my = $get['my'] ?:"list";
       $id = $get['id']?:"id";
       if($my == 'edit' && !empty($id)){
           $row = $this->db->qrlistrow($id);
       }
       include usertem.'usdt.php';
   }
   public function Hang_qrlist($get){
       if($this->islogin_user != 1)Commontc::falsetc("请先登录",rethreffun('/login'));
       $my = $get['my'] ?:"list";
       $id = $get['id']?:"id";
       if($my == 'edit' && !empty($id)){
           $row = $this->db->qrlistrow($id);
       }
       
       $token = aes256auth(json_encode(['pid'=>$this->uid,'key'=>$this->userrow['key']]),$this->Hang_Token);
       $qrcode = $this->CurlUrl->qr_token((is_https() ? 'https://' : 'http://').$_SERVER['HTTP_HOST'],$token);
       
       include usertem.'Hang_qrlist.php';
   }
   public function info(){
       if($this->islogin_user != 1)Commontc::falsetc("请先登录",rethreffun('/login'));
       list($phone, $email) = maskSensitiveInfo($this->userrow['phone'], $this->userrow['email']);
       
       list($pwd , $paypass) = test_mask([$this->userrow['pass'],$this->userrow['pay_pass']]);
       
       $rsakey = md5($this->userrow['key'].$this->userrow['pid']);
       $paypwd = aes256auth($_SESSION['paypwd'] , SYS_KEY , "DECODE") === $this->uid;
       
       include usertem.'info.php';
    }
    public function Pay_Vip($get){
        if($this->islogin_user != 1)Commontc::falsetc("请先登录",rethreffun('/login'));
        if(($get['pid'] && $get['trade_no'] && $get['sign'] && $get['trade_status'] == 'TRADE_SUCCESS') || (!empty($get['token']))){
            Tips::success("支付成功！",'充值成功','/user/Pay_Vip');
        }
        $meals = $this->conf->pay_meal;
        if (!is_array($meals)) $meals = [];
        $html = user_money_meal_temp($meals);
        include usertem.'Pay_Vip.php';
    }
    public function packages($get){
        if($this->islogin_user != 1)Commontc::falsetc("请先登录",rethreffun('/login'));
        if(($get['pid'] && $get['trade_no'] && $get['sign'] && $get['trade_status'] == 'TRADE_SUCCESS') || (!empty($get['token']))){
            Tips::success("支付成功！",'购买成功','/user/packages');
        }
        include usertem.'packages.php';
    }
    public function Work(){
        if($this->islogin_user != 1)Commontc::falsetc("请先登录",rethreffun('/login'));
        
        include usertem.'Work.php';
    }
    
    public function pay_cs($get){
        if($this->islogin_user != 1)Commontc::falsetc("请先登录",rethreffun('/login'));
        if(($get['pid'] && $get['trade_no'] && $get['sign'] && $get['trade_status'] == 'TRADE_SUCCESS') || (!empty($get['token']))){
            Tips::success("支付成功！",'购买成功','/user/packages');
        }
        include usertem.'pay_cs.php';
    }
    public function Plugin(){
        if($this->islogin_user != 1)Commontc::falsetc("请先登录",rethreffun('/login'));
        include usertem.'Plugin.php';
    }
    public function juhe(){
        if($this->islogin_user != 1)Commontc::falsetc("请先登录",rethreffun('/login'));
        $token = aes256auth($this->uid,SYS_KEY);
        if($this->conf->juheshoukuan == 0){
            $this->echomsg("Tips",'管理员未开启聚合收款');
        }
        $code_url = $this->httphost . 'juhe/paypage/'.urlencode($token);
        include usertem.'juhe.php';
    }
    
}

?>